package com.xfusion.chatglm.data.domain.openai.service.rule.impl;

import com.xfusion.chatglm.data.domain.openai.annotation.LogicStrategy;
import com.xfusion.chatglm.data.domain.openai.model.aggregates.ChatProcessAggregate;
import com.xfusion.chatglm.data.domain.openai.model.entity.RuleLogicEntity;
import com.xfusion.chatglm.data.domain.openai.model.entity.UserAccountQuotaEntity;
import com.xfusion.chatglm.data.domain.openai.model.valobj.LogicCheckTypeVO;
import com.xfusion.chatglm.data.domain.openai.model.valobj.UserAccountStatusVO;
import com.xfusion.chatglm.data.domain.openai.service.rule.ILogicFilter;
import com.xfusion.chatglm.data.domain.openai.service.rule.factory.DefaultLogicFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 账户校验
 */
@Slf4j
@Component
@LogicStrategy(logicMode = DefaultLogicFactory.LogicModel.ACCOUNT_STATUS)
public class AccountStatusFilter implements ILogicFilter<UserAccountQuotaEntity> {
    @Override
    public RuleLogicEntity<ChatProcessAggregate> filter(ChatProcessAggregate chatProcessAggregate,UserAccountQuotaEntity data) throws Exception {
        //账户可用，直接放行
        if (UserAccountStatusVO.AVAILABLE.equals(data.getUserAccountStatusVO())){
            return RuleLogicEntity.<ChatProcessAggregate>builder().type(LogicCheckTypeVO.SUCCESS).data(chatProcessAggregate).build();
        }
        return RuleLogicEntity.<ChatProcessAggregate>builder().info("您的帐户已冻结，暂时不可使用。如有疑问，请联系作者捏~~~").type(LogicCheckTypeVO.REFUSE).data(chatProcessAggregate).build();
    }
}
